package cn.hl.hm.controller.driver.notice;

import cn.hl.hm.entity.DriverOwnInfo;
import cn.hl.hm.service.DriverOwnInfoService;
import cn.hl.hm.util.InfoCode;
import cn.hl.hm.util.Result;
import cn.hl.hm.util.token.TokenUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by tarzan on 2017/11/22.
 */
@Controller
@RequestMapping("/driver/notice")
public class NoticeController {
    private static final Logger logger = LoggerFactory.getLogger(NoticeController.class);
    @Autowired
    private DriverOwnInfoService driverOwnInfoService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String info(@CookieValue(required = false,value = "driverToken") String driverToken,
                       @RequestParam(required = false) Integer id,
                       @RequestParam(required = false,defaultValue = "10") Integer pageCount,
                       HttpServletRequest request, HttpServletResponse response) throws IOException {
        logger.info("司机---基本信息---driver/info");
        request.setCharacterEncoding("UTF-8");
        try {
            Integer driverId = TokenUtil.getTokenBean(driverToken).getId();
            List<DriverOwnInfo> driverOwnInfoList=driverOwnInfoService.selectDriverOwnInfo(driverId,id,pageCount);
            Result.ok(driverOwnInfoList, InfoCode.SUCCESS, response);
        } catch (Exception e) {
            e.printStackTrace();
            Result.ok(null, InfoCode.FAILURE, response);
        }
        return null;
    }

}
